<!-- 注销记录编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate?'修改注销记录':'添加注销记录'"
    :visible="visible"
    width="550px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
    :close-on-click-modal="false">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="100px">

      <el-form-item label="用户id:" prop="member_id">
        <el-input-number
          :min="0"
          v-model="form.member_id"
          placeholder="请输入用户id"
          controls-position="right"
          class="ele-fluid ele-text-left"/>
      </el-form-item>

      <el-form-item
        label="玩家账号:"
        prop="member_account">
        <el-input
          :maxlength="20"
          v-model="form.member_account"
          placeholder="请输入玩家账号"
          clearable/>
      </el-form-item>

      <el-form-item
        label="申请时间:"
        prop="add_time">
        <el-input
          :maxlength="20"
          v-model="form.add_time"
          placeholder="请输入申请时间"
          clearable/>
      </el-form-item>

      <el-form-item
        label="注销时间:"
        prop="log_off_time">
        <el-input
          :maxlength="20"
          v-model="form.log_off_time"
          placeholder="请输入注销时间"
          clearable/>
      </el-form-item>

      <el-form-item label="注销状态:1=未注销,2=已注销,3=取消注销:" prop="status">
        <el-input-number
          :min="0"
          v-model="form.status"
          placeholder="请输入注销状态:1=未注销,2=已注销,3=取消注销"
          controls-position="right"
          class="ele-fluid ele-text-left"/>
      </el-form-item>

      <el-form-item
        label="注销原因:"
        prop="reason">
        <el-input
          :maxlength="20"
          v-model="form.reason"
          placeholder="请输入注销原因"
          clearable/>
      </el-form-item>

      <el-form-item
        label="其他原因:"
        prop="reason_other">
        <el-input
          :maxlength="20"
          v-model="form.reason_other"
          placeholder="请输入其他原因"
          clearable/>
      </el-form-item>

      <el-form-item
        label="提出建议:"
        prop="propose">
        <el-input
          :maxlength="20"
          v-model="form.propose"
          placeholder="请输入提出建议"
          clearable/>
      </el-form-item>

      <el-form-item label="审核状态:1=未审核，2=已审核，3=已拒绝:" prop="audit_status">
        <el-input-number
          :min="0"
          v-model="form.audit_status"
          placeholder="请输入审核状态:1=未审核，2=已审核，3=已拒绝"
          controls-position="right"
          class="ele-fluid ele-text-left"/>
      </el-form-item>

      <el-form-item
        label="审核时间:"
        prop="audit_time">
        <el-input
          :maxlength="20"
          v-model="form.audit_time"
          placeholder="请输入审核时间"
          clearable/>
      </el-form-item>

      <el-form-item label="审核人员id:" prop="audit_admin_id">
        <el-input-number
          :min="0"
          v-model="form.audit_admin_id"
          placeholder="请输入审核人员id"
          controls-position="right"
          class="ele-fluid ele-text-left"/>
      </el-form-item>

      <el-form-item
        label="注销ip:"
        prop="log_off_ip">
        <el-input
          :maxlength="20"
          v-model="form.log_off_ip"
          placeholder="请输入注销ip"
          clearable/>
      </el-form-item>

      <el-form-item
        label="设备号:"
        prop="device">
        <el-input
          :maxlength="20"
          v-model="form.device"
          placeholder="请输入设备号"
          clearable/>
      </el-form-item>

      <el-form-item label="来源类型 1=sdk 2=盒子:" prop="type">
        <el-input-number
          :min="0"
          v-model="form.type"
          placeholder="请输入来源类型 1=sdk 2=盒子"
          controls-position="right"
          class="ele-fluid ele-text-left"/>
      </el-form-item>
                </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
// import uploadImage from '@/components/uploadImage'

export default {
  name: 'MemberLogOffEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  // components: {uploadImage},
  data() {
    return {
      // 表单数据
      form: Object.assign({status:1}, this.data),
      // 表单验证规则
      rules: {
              member_id: [
          {required: true, message: '请输入用户id', trigger: 'blur'}
        ],
                  member_account: [
          {required: true, message: '请输入玩家账号', trigger: 'blur'}
        ],
                  add_time: [
          {required: true, message: '请输入申请时间', trigger: 'blur'}
        ],
                  log_off_time: [
          {required: true, message: '请输入注销时间', trigger: 'blur'}
        ],
                  status: [
          {required: true, message: '请输入注销状态:1=未注销,2=已注销,3=取消注销', trigger: 'blur'}
        ],
                  reason: [
          {required: true, message: '请输入注销原因', trigger: 'blur'}
        ],
                  reason_other: [
          {required: true, message: '请输入其他原因', trigger: 'blur'}
        ],
                  propose: [
          {required: true, message: '请输入提出建议', trigger: 'blur'}
        ],
                  audit_status: [
          {required: true, message: '请输入审核状态:1=未审核，2=已审核，3=已拒绝', trigger: 'blur'}
        ],
                  audit_time: [
          {required: true, message: '请输入审核时间', trigger: 'blur'}
        ],
                  audit_admin_id: [
          {required: true, message: '请输入审核人员id', trigger: 'blur'}
        ],
                  log_off_ip: [
          {required: true, message: '请输入注销ip', trigger: 'blur'}
        ],
                  device: [
          {required: true, message: '请输入设备号', trigger: 'blur'}
        ],
                  type: [
          {required: true, message: '请输入来源类型 1=sdk 2=盒子', trigger: 'blur'}
        ],
            },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http.post('/memberlogoff/edit', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
</style>
